package demoMod.invincibleOne.powers;

import com.evacipated.cardcrawl.mod.stslib.powers.abstracts.TwoAmountPower;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.PowerStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.rooms.MonsterRoom;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.enums.CardTagsEnum;
import demoMod.invincibleOne.interfaces.IOnCurseAddToHand;

import java.util.stream.Collectors;

public class UserProtocolPower extends TwoAmountPower implements IOnCurseAddToHand {
    public static final String POWER_ID = InvincibleOneMod.makeID("UserProtocolPower");
    private static final PowerStrings powerStrings = CardCrawlGame.languagePack.getPowerStrings(POWER_ID);
    public static final String NAME = powerStrings.NAME;
    public static final String[] DESC = powerStrings.DESCRIPTIONS;

    private final int initTriggerAmount;

    public UserProtocolPower(AbstractCreature owner, int triggerAmount, int healAmount) {
        this.owner = owner;
        this.ID = POWER_ID;
        this.name = NAME;
        this.amount2 = triggerAmount;
        this.amount = healAmount;
        this.initTriggerAmount = triggerAmount;
        this.updateDescription();
        loadRegion("painfulStabs");
        this.type = PowerType.DEBUFF;
    }

    @Override
    public void updateDescription() {
        this.description = String.format(DESC[0], this.amount2, this.amount);
    }

    public void onCardDraw(AbstractCard card) {
        if (card.type == AbstractCard.CardType.STATUS || card.type == AbstractCard.CardType.CURSE || card.hasTag(CardTagsEnum.VIRUS)) {
            onCurseAddToHand(card);
        }
    }

    @Override
    public void onCurseAddToHand(AbstractCard c) {
        this.amount2--;
        if (this.amount2 <= 0) {
            this.flash();
            this.amount2 = this.initTriggerAmount;
            for (AbstractMonster m : AbstractDungeon.getMonsters().monsters.stream().filter(m -> !m.isDeadOrEscaped()).collect(Collectors.toList())) {
                if (m.maxHealth >= 100 && AbstractDungeon.getCurrRoom().getClass().equals(MonsterRoom.class)) {
                    m.heal(this.amount * 2);
                } else {
                    m.heal(this.amount);
                }
            }
        }
    }
}
